package com.qk.service.impl;

import com.qk.mapper.BusinessMapper;
import com.qk.mapper.ClueMapper;
import com.qk.service.ReportService;
import com.qk.vo.OverviewVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ReportServiceimpl  implements ReportService {
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;
    @Override
    public OverviewVo getOverviewlist() {
        Object overview = redisTemplate.opsForValue().get("overview");
        if(overview != null)
        {
            return (OverviewVo) overview;
        }
        OverviewVo  businessOverView = businessMapper.getOverview();
        OverviewVo  clueOverView = clueMapper.getOverview();
        BeanUtils.copyProperties(businessOverView, clueOverView, "clueTotal", "clueWaitAllot", "clueWaitFollow", "clueFollowing", "clueFalse", "clueConvertBusiness");
        redisTemplate.opsForValue().set("overview",clueOverView,1, TimeUnit.MINUTES);
        return clueOverView;
    }
}
